package close.mazegame.entity.projectile;

import box2dLight.PointLight;
import close.mazegame.art.MiscArt;
import close.mazegame.collision.Collidable;
import close.mazegame.entity.Tank;
import close.mazegame.level.Level;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;

public class TestProjectile extends Projectile {
	
	private static final float START_LIGHT_BRIGHTNESS = 1.0f;
	private static final float END_LIGHT_BRIGHTNESS = 0.0f;
	private static final float LIFETIME = 1.0f;
	
	private PointLight pl;
	private float timer = 0.0f;

	public TestProjectile(Vector2 pos, Level level, float angle) {
		super(pos, level, angle);
		this.mainTexture = MiscArt.testProjectile;
		this.pl = level.addPointLight(body, 64,  new Color(1.0f, 0.7f, 0.4f, START_LIGHT_BRIGHTNESS), 1.0f, 0);
		this.pl.setXray(true);
	}

	public PointLight getLight() {
		return pl;
	}

	@Override
	protected float getSpeed() {
		return 8.0f;
	}
	
	public void dispose(){
		super.dispose();
		pl.remove();
	}

	@Override
	public void startContact(Collidable other) {
		if(other instanceof Tank){
			this.remove();
		}
	}

	@Override
	public void update(float delta) {
		timer += delta;
		float lightStrength = Interpolation.sineIn.apply(START_LIGHT_BRIGHTNESS, END_LIGHT_BRIGHTNESS, timer / LIFETIME);
		pl.setColor(1.0f, 0.45f, 0.0f, lightStrength);
		if(timer > LIFETIME){
			this.remove();
		}
	}

	@Override
	public void endContact(Collidable other) {
		
	}

}
